<template>
    <div>
        <div>
            <div style="">
                <Modal v-model="modalSs11006" :title="title" width="900" cancel-text="关闭" style="position:relative;">
                    <Form :disabled="disableSubmit01" ref="dataSs11006" :model="dataSs11006" :rules="rules" inline :label-width="160"
                          >
                        <table style="width:100%;">
                            <tr>
                                <td style="">
                                    <FormItem label="人员姓名" prop="ssbd0001">
                                        <dictSelect :sel_val='dataSs11006.ssbd0001' dicType="service"
                                                    :bindData.sync="dataSs11006.ssbd0001" :serviceParam="serviceParam"
                                                    dictService="/api/ac/subsistence/ss17002Service/getAssistanceMemberList"
                                                    class="itemStyle" style="width: 200px"    />
                                    </FormItem>
                                </td>
                                <td>
                                    <FormItem label="财产类型" prop="ssbd0002">
                                        <dictSelect :sel_val='dataSs11006.ssbd0002' dictCode="possessiontype"
                                                    :bindData.sync="dataSs11006.ssbd0002" style="width: 200px"
                                                    clearable   />
                                    </FormItem>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <FormItem label="财产明细类:" prop="ssbd0011">

                                        <!--                                        家庭经营性财产-->
                                        <div id="a">
                                            <dictSelect :sel_val='dataSs11006.ssbd0011' dictCode="operationalproperty"
                                                        v-if="operationalpropertytype"
                                                        :bindData.sync="dataSs11006.ssbd0011" style="width: 200px"
                                                        clearable   />
                                        </div>
                                        <!--                                        家庭高档消费品-->
                                        <div id="b">
                                            <dictSelect :sel_val='dataSs11006.ssbd0011' dictCode="consumergoods"
                                                        v-if="consumergoodstype"
                                                        :bindData.sync="dataSs11006.ssbd0011" style="width: 200px"
                                                        clearable   />
                                        </div>
                                        <!--                                        其他家庭财产-->
                                        <div id="c">
                                            <dictSelect :sel_val='dataSs11006.ssbd0011' dictCode="otherproperty"
                                                        v-if="otherpropertytype"
                                                        :bindData.sync="dataSs11006.ssbd0011" style="width: 200px"
                                                        clearable   />
                                        </div>

                                    </FormItem>
                                </td>
                                <td>
                                    <FormItem label="财产明细类说明" prop="ssbd0012">
                                        <Input v-model="dataSs11006.ssbd0012" placeholder=""
                                               style="width: 200px"   ></Input>
                                    </FormItem>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <FormItem label="财产总估值" prop="ssbd0005">
                                        <Input v-model="dataSs11006.ssbd0005" placeholder="" style="width: 200px"
                                               type="number" ></Input>
                                    </FormItem>
                                </td>
                                <td>
                                    <FormItem label="是否计入个人收入" prop="ssbd0006">
                                        <dictSelect :sel_val='dataSs11006.ssbd0006' dictCode="yesorno"
                                                    :bindData.sync="dataSs11006.ssbd0006" style="width: 200px"
                                                    clearable   />
                                    </FormItem>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <FormItem label="计入开始时间">
                                        <DatePicker type="date"  v-model="dataSs11006.ssbd0009" style="width: 200px"
                                                    :editable="false"></DatePicker>
                                        <!--                                        <DatePicker type="date" placeholder="Select date" style="width: 200px"></DatePicker>-->
                                    </FormItem>
                                </td>
                                <td>
                                    <FormItem label="计入月数">
                                        <Input v-model="dataSs11006.ssbd0008"
                                               style="width: 200px"   />
                                    </FormItem>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <FormItem label="计入结束时间">
                                        <DatePicker type="date" v-model="dataSs11006.ssbd0010" style="width: 200px"
                                                        />
                                    </FormItem>
                                </td>
                                <td>
                                    <FormItem label="月计入个人收入金额">
                                        <Input v-model="dataSs11006.ssbd0007"
                                               style="width: 200px"   />
                                    </FormItem>
                                </td>
                            </tr>
                        </table>
                    </Form>
                    <div slot="footer">
                        <Button type="text" size="large" @click="modalSs11006 = false">关闭</Button>
                    </div>
                </Modal>
            </div>
            <div style="margin-top: 10px">
                <Table :columns="columns" :data="tableData" :loading="Loading" border>
                    <template slot-scope="{ row, index }" slot="action">
                        <Button type="info" size="small" @click="handleEdit(index)" style="margin-right:5px">详情</Button>
                    </template>
                </Table>
            </div>
        </div>
        <div style="height:40px;line-height:40px;margin-top:10px;text-align: center ">
            <Button @click="prevStep">上一步</Button>
            <Button type="primary" @click="nextStep" style="margin-left:20px">下一步
            </Button>
        </div>
    </div>
</template>
<script>
    import {getCityDBAppraising} from '@/api/subsistenceAlowances'
    import {date2str, iteminf, updateOrder} from '@/api/eventlist'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'
    import {postAction} from '@/api/request'
    import DateFormat from '@/plugins/format.js'

    export default {
        created() {
            let that = this;
            that.familyInfo = that.$parent.familyInfo;
            that.ss11001Id = that.familyInfo.ssca0001;
            that.queryParam.azcp0500 = that.ss11001Id;
            this.loadData();
            that.serviceParam.azcp0500 = that.ss11001Id;
        },
        mixins: [CommonMixin],
        components: {
            dictSelect,
        },
        data() {
            return {
                title: '',
                otherpropertytype: false,
                operationalpropertytype: true,
                consumergoodstype: false,
                ssbd0011type: '',
                ss11001Id: '',
                familyInfo: {},
                serviceParam: {
                    azcp0500: ''
                },
                queryParam: {},
                medicalInsuranceState: true, //医保联动状态
                disableSubmit: false,
                disableSubmit01: true, //页面只读
                modalSs11006: false,
                dataSs11006: {},
                tableData: [],
                Loading: false,
                family_url: '',
                support_id: '',
                family_idInfo: {},
                next_params: {},
                itemid: this.$route.params.itemid || '',
                property_url: '',
                info_url: '',
                see: this.$route.params.see || false,
                code: this.$route.params.code,
                url: {
                    list: "/api/ac/subsistence/ss17006Service/getPageList",
                    delete: "/api/ac/subsistence/ss17006Service/deleteData"
                },
                str: this.$route.params.serialNumber,
                idcardNumber: this.$route.params.idcardNumber,
                columns: [
                    {
                        title: '人员姓名',
                        align: 'center',
                        key: 'ssbd0001_name'
                    },
                    {
                        title: '财产类型',
                        align: 'center',
                        key: 'ssbd0002_name'
                    },
                    {
                        title: '财产总估值',
                        align: 'center',
                        key: 'ssbd0005'
                    },
                    {
                        title: '是否计入个人收入',
                        align: 'center',
                        key: 'ssbd0006_name'
                    },
                    {
                        title: '计入开始时间',
                        align: 'center',
                        key: 'ssbd0009',
                        render: (h, params) => {
                            let value = params.row.ssbd0009
                            if (typeof (value) === 'undefined' || value === null || value === '' || value === undefined) {
                                value = '--'
                            } else {
                                value = DateFormat(value, 'YYYY-MM-DD')
                            }
                            return h('span', value + ' ')
                        }
                    },
                    {
                        title: '计入结束时间',
                        align: 'center',
                        key: 'ssbd0010',
                        render: (h, params) => {
                            let value = params.row.ssbd0010
                            if (typeof (value) === 'undefined' || value === null || value === '' || value === undefined) {
                                value = '--'
                            } else {
                                value = DateFormat(value, 'YYYY-MM-DD')
                            }
                            return h('span', value + ' ')
                        }
                    },
                    {
                        title: '计入月数',
                        align: 'center',
                        key: 'ssbd0008',
                        render: (h, params) => {
                            let value = params.row.ssbd0008
                            if (typeof (value) === 'undefined' || value === null || value === '' || value === undefined) {
                                value = '--'
                            }
                            return h('span', value + ' ')
                        }
                    },
                    {
                        title: '月计入个人收入金额',
                        align: 'center',
                        key: 'ssbd0007',
                        render: (h, params) => {
                            let value = params.row.ssbd0007
                            if (typeof (value) === 'undefined' || value === null || value === '' || value === undefined) {
                                value = '--'
                            }
                            return h('span', value + ' ')
                        }
                    },
                    {
                        title: '操作',
                        slot: 'action',
                        align: 'center',
                        width: '200px',
                      fixed:'right'
                    }
                ],
                fieldsToValidate02: ["ssbd0001", "ssbd0002", "ssbd0011", "ssbd0012", "ssbd0005", "ssbd0006"],
                rules: {
                },
                ruleSsbd0011: [],
                possessiontype: [],
                data1: [],
                data2: [],
                data3: [],
                dataF1: [],
                dataF2: [
                    {
                        'key': '1',
                        'value': '家庭支出'
                    }
                ],
                modal: false,
                order_state: this.$route.params.order_state,
                detailData: [],
                form_params: {
                    ss11001Data: {},
                    ss11002Data: [],
                    ss11003Data: [],
                    ss11004Data: [],
                    ss11005Data: [],
                    ss11006Data: [],
                    ss11007Data: [],
                    ss11008Data: [],
                    ss11009Data: [],
                    ss11010Data: [],
                    ss11012Data: [],
                    ss12001Data: {}
                },
                data4: [],
                basicproperty_arr: [],
                errorTitle: '错误'
            }
        },
        watch: {
            "dataSs11006.ssbd0002": function (value,oldVal) {
                let that = this;
                if(oldVal){
                    that.dataSs11006.ssbd0011 = undefined;
                }
                if (value == '200') {
                    that.operationalpropertytype = true;
                    that.consumergoodstype = false;
                    that.otherpropertytype = false;
                } else if (value == '300') {
                    that.operationalpropertytype = false;
                    that.consumergoodstype = true;
                    that.otherpropertytype = false;
                } else if (value == '900') {
                    that.operationalpropertytype = false;
                    that.consumergoodstype = false;
                    that.otherpropertytype = true;
                }
            }
        },
        methods: {
            prevStep() {
                this.$emit('prevStep')
            },
            nextStep() {
                this.$emit('nextStep')
            },
            nextPage() {
                this.$router.push({
                    name: 'db_houseproperty',
                    params: this.next_params
                })
            },
            handleAdd() {
                this.$refs['dataSs11006'].resetFields();
                let that = this;
                that.title = "录入";
                that.disableSubmit = false;
                // let record = {};
                that.modalSs11006 = true;
                that.dataSs11006 = new Object();
                that.dataSs11006.ssbd0009 = undefined;
                that.dataSs11006.ssbd0010 = undefined;
            },
            handleEdit(index) {
                let that = this;
                that.title = "编辑";
                that.disableSubmit = false;
                let record = that.tableData[index];
                if (record.id) {
                    that.modalSs11006 = true;
                    that.dataSs11006 = Object.assign({}, record);
                    if (record.ssbd0009 != undefined) {
                        that.dataSs11006.ssbd0009 = new Date(record.ssbd0009);
                    }
                    if (record.ssbd0010 != undefined) {
                        that.dataSs11006.ssbd0010 = new Date(record.ssbd0010);
                    }
                } else {
                    that.modalSs11006 = false
                }
            },
            handleDetail(index) {
                let that = this;
                that.title = "详情";
                that.disableSubmit = true;
                let record = that.tableData[index];
                if (record.id) {
                    that.modalSs11006 = true;
                    that.dataSs11006 = Object.assign({}, record);
                    that.dataSs11006.ssbd0009 = new Date(record.ssbd0009);
                    that.dataSs11006.ssbd0010 = new Date(record.ssbd0010);
                } else {
                    that.modalSs11006 = false
                }
            },
            handleSubmit(name) {
                let that = this;
                let validate = true;
                let err_msg = [];
                for (let item of that.fieldsToValidate02) {
                    that.$refs[name].validateField(item, (error) => {
                        if (error) {
                            validate = false;
                            err_msg.push(that.rules[item][0].message);
                        }
                    })
                }
                if (validate) {
                    let dataParam = {}
                    that.Loading = true;
                    dataParam = Object.assign({}, that.dataSs11006);
                    let url = "/api/ac/subsistence/ss17006Service/createData";
                    if (dataParam.id != null) {
                        url = "/api/ac/subsistence/ss17006Service/updateData";
                    }
                    dataParam.ssbd0009=DateFormat(that.dataSs11006.ssbd0009, 'YYYY-MM-DD');
                    dataParam.ssbd0010=DateFormat(that.dataSs11006.ssbd0010, 'YYYY-MM-DD');
                    postAction(url, dataParam).then((res) => {
                        if (res.data.errcode != 0) {
                            this.$Message.error(res.data.errmsg);
                        } else {
                            this.modalFormOk();
                            this.modalSs11006 = false;
                        }
                    }).finally(() => {
                        that.Loading = false;
                    });
                } else {
                    that.$Message.error(err_msg[0]);
                    return;
                }
            },
            next() {
                this.$router.push({
                    name: 'db_houseproperty',
                    params: this.next_params
                })
            },
        },
        mounted() {

        }
    }
</script>

<style scoped>
    /deep/ .ivu-form-item-error-tip {
        display: none;
    }

    .ivu-form-item {
        margin-bottom: 0px;
    }

    .itemStyle {
        width: 180px
    }
</style>
<style scoped>
    /deep/ .ivu-form-item-error-tip {
        display: none;
    }

    .ivu-form-item {
        margin-bottom: 0px;
    }

    .itemStyle {
        width: 180px
    }

    .head-img1 {
        height: 200px;
        width: 250px;
        margin-top: 15px;
    }

    .head-img {
        height: 200px;
        width: 250px;
    }

    .imgBackColor {
        background-color: WhiteSmoke;
        height: 250px;
    }

    .positiveTDiv {
        height: 240px;
        width: 75px;
        line-height: 240px;
        background-color: #7CCD7C;
        margin-bottom: 10px;
        color: white;
        font-size: 14px;
        font-weight: 700;
    }
</style>
